package io.github.junxworks.junx.stream.handler;

import io.github.junxworks.junx.core.util.StringUtils;
import io.github.junxworks.junx.event.EventChannelHandler;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

@Getter
@Setter
public abstract class AbstractDataHandler implements EventChannelHandler {

    protected AtomicLong eventProcessingCount = new AtomicLong(0);

    protected String outputTopic;

    protected Map<String, Object> globalParams;

    public boolean shouldPassEvent() {
        return StringUtils.notNull(outputTopic);
    }

    public void incrCount() {
        eventProcessingCount.incrementAndGet();
    }

    public void decrCount() {
        eventProcessingCount.decrementAndGet();
    }

    public boolean isDone() {
        return eventProcessingCount.get() == 0;
    }
}
